package com.ease.framework.gef4p.figures.impl.edge {

   import mx.core.UIComponent;

   public class EdgeArraw extends UIComponent {
      private var arrowWidth:Number = 5; //设置三角形的底边长
      private var arrowHeight:Number = 9; //设置三角形的高

      private var source_x:Number = 0;
      private var source_y:Number = 0;

      public function EdgeArraw() {

         this.x = 50;
         this.y = 50;
      }

      public function render():void {

      }

      public function setSourcePoint(x:int, y:int):void {
         source_x = x;
         source_y = y;
      }

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
         super.updateDisplayList(unscaledWidth, unscaledHeight);
         dragRender(this.parent as EdgeFigure);
      }

      public function dragRender(parent:EdgeFigure):void {

         graphics.clear();

         var tb:Bend = parent.getTargetBend();
         if (tb != null) {
            var tb_s:Bend = tb.getFront();
            source_x = tb_s.x;
            source_y = tb_s.y;

            this.x = tb.x;
            this.y = tb.y;

            var angle:Number = Math.atan2(tb.y - source_y, tb.x - source_x);

            var point_x1:Number = 0 - arrowHeight * Math.cos(angle) - arrowWidth * Math.sin(angle) * 0.7;
            var point_y1:Number = 0 - arrowHeight * Math.sin(angle) + arrowWidth * Math.cos(angle) * 0.7;

            var point_x2:Number = 0 - arrowHeight * Math.cos(angle) + arrowWidth * Math.sin(angle) * 0.7;
            var point_y2:Number = 0 - arrowHeight * Math.sin(angle) - arrowWidth * Math.cos(angle) * 0.7;

            graphics.beginFill(0, 1);
            graphics.lineStyle(1, 0x000000, 1);
            graphics.moveTo(0, 0);
            graphics.lineTo(point_x1, point_y1);
            graphics.moveTo(0, 0);
            graphics.lineTo(point_x2, point_y2);
            graphics.lineTo(point_x1, point_y1);
            graphics.endFill();
         }
      }
   }
}